#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

void my_bubble_qsort(void* base, size_t num, size_t size, int(*compare)(const void* p1, const void* p2));
int compare(const void* p1, const void* p2);

int main()
{
	int arr[] = { 3,9,4,1,5,7,6,0,8,2 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
	my_bubble_qsort(arr, sz, sizeof(int), compare);
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
	return 0;
}

int compare(const void* p1, const void* p2)
{
	return *(int*)p1 - *(int*)p2;
}

void my_bubble_qsort(void* base, size_t num, size_t size, int(*compare)(const void* p1, const void* p2))
{
	int i = 0;
	int j = 0;
	int k = 0;
	for (i = 0; i < num; i++)
	{
		for (j = i + 1; j < num; j++)
		{
			if (compare((char*)base + size * i, (char*)base + size * j) > 0)
			{
				char* p1 = (char*)base + size * i;
				char* p2 = (char*)base + size * j;
				for (k = 0; k < size; k++)
				{
					char temp = *p1;
					*p1 = *p2;
					*p2 = temp;
					p1++;
					p2++;
				}
			}
		}
	}
}